#ifndef MOOSQLITE_H
#define MOOSQLITE_H
#include "MooCpp.h"

#include "sqlite/sqlite3.h"

class MooNumber;

class MooSqlite
{
public:
    typedef enum{OPEN_FAILED = 1} MoosqliteError;
    typedef vector< map <string, string> > SQLParam;
    typedef vector< map <string, string> > AllResult;
    typedef map<string, string> RowResult;
    typedef vector<string> ColResult;

public:
    MooSqlite(string dbPath);
    ~MooSqlite();
    bool getRow(RowResult *result, string sql, SQLParam param);
    bool getAll(AllResult *result, string sql, SQLParam param);
    bool getCol(ColResult *result, string sql, SQLParam param);
    bool getRow(RowResult *result, string sql);
    bool getAll(AllResult *result, string sql);
    bool getCol(ColResult *result, string sql);

    void setData(string key, string value);
    void setData(string key, MooNumber value);
    void setExpr(string key, string value);
    
    bool query(string sql);
    bool insert(string table);
    bool update(string table, string pk, string id);
    bool remove(string table, string pk, string id);
    
    int getInsertId();
    
    string getError();
    void setError(string errmsg);

private:
    sqlite3 *_conn;
    bool _isOpen;
    char * _errmsg;
    
private:
    bool open(string dbPath);
    void close();
    void quote(string value);
};

#endif // MOOSQLITE_H
